home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / emulator / bsvc-1.000 / bsvc-1 / bsvc-1.0.4 / src / Assemblers / hecasm / asm.h next >
C/C++ Source or Header  |  1995-07-26  |  6KB  |  207 lines

  1. /* asm.h constants and type decarations */
  2.  
  3. #include <stdio.h>
  4. #include <ctype.h>
  5.  
  6. #define NCPS    32        /* Characters per symbol */
  7. #define CLMAX    100        /* Code bytes, line */
  8. #define CBMAX    8        /* Code bytes, object */
  9. #define USERMAX    512        /* User names 512 or 2048! */
  10. #define SRCMAX    128        /* Source line length */
  11. #define ERRMAX    4        /* Maximum errors per line */
  12. #define REFMAX    4000        /* Maximum reference entries */
  13. #define LREFMAX    16        /* References per listing line */
  14. #define MAXADR     0X10000    
  15. #define TRUE    -1
  16. #define FALSE    0
  17. #define WORD    0x0ffff
  18. #define BYTE    0x0ff
  19.  
  20. /* The next constant is important. Much of this assembler is keyed on it
  21. * It determines the fundamental word size of a machine.  It is 1 
  22. * for byte, and 2 for word.  This constant determines what size word 
  23. * is coded by codew(), and output by cflush() and outlisting(). */
  24.  
  25. #define WSIZE    2        /* number of bytes in machine word */
  26.  
  27. /* default radixes */
  28. #define    HEX    0
  29. #define    DEC    1
  30. #define    OCT    2
  31. #define    BIN    3
  32.  
  33.  
  34. /*
  35.  * Reference chain structure
  36.  */
  37. struct reflst {
  38.     int r_stmtno;        /* The statement number */
  39.     struct reflst *r_chain;    /* Chain pointer */
  40. };
  41.  
  42.  
  43. /*
  44.  * Symbol table structure.
  45.  * Used in both the user symbol table and
  46.  * the opcode table.
  47.  */
  48. struct sym {
  49.     char s_name[NCPS];    /* Name */
  50.     char s_type;        /* Type (pst only)*/
  51.     char s_flag;        /* Some flags (ust only)*/
  52.     struct reflst *s_ref;    /* Reference chain pointer (ust only)*/
  53.     int  s_value;        /* Value */
  54.         int  s_used;            /* valid flag (ust only)*/
  55. };
  56.  
  57.  
  58. /*
  59.    Instruction operand structures:
  60. */
  61. /*    Data:
  62.     This data structure contains the parsing information for the
  63.        data fields of HECTOR instructions.  Each data field includes
  64.        1) the addressing mode of the operand,
  65.        2) the actual binary pattern of the specifying addressing
  66.          mode,
  67.        3) the register number implied (used) by the operand, and
  68.        4) the extension word, if any.                */
  69.  
  70. struct d_operand 
  71.     {
  72.     int    mode;        /* Addressing mode             */
  73.     int    mode_bits;    /* Bit pattern of mode            */
  74.     int    reg;        /* Bit pattern of register        */
  75.     int    ext_word;    /* Value of extension word, if any    */
  76.     int    parse_error;    /* Flag:  1=error; 0=OK            */
  77.     };
  78.  
  79. /*    Branch:
  80.         This data structure contains the parsing information for branch
  81.        condition codes.  There are 16 branch conditions.        */
  82. struct b_operand 
  83.     {
  84.     int    mode_bits;    /* Bit pattern of branch condition    */
  85.     int    parse_error;    /* Flag:  1=error; 0=OK            */
  86.     };
  87.  
  88.  
  89.  
  90. /*
  91.  * Types.
  92.  */
  93. /* These types are very important.  They are stored in the permanent 
  94. * symbol table and determine how a statement will be handled in 
  95. * asm2.c. Types should also be added here for the opcodes to be 
  96. * included in the instruction set of this assembler.  Group the 
  97. * instructions into classes to be handled the same (ie. two operand 
  98. /* instructions with the same addressing modes) */
  99. #define GR_ORG       0        /* .org */  
  100. #define GR_PASCII     1        /* .ascii */
  101. #define GR_LIST      2        /* .list pseudo-op */
  102. #define GR_UASCII     3        /* .uascii */
  103. #define GR_WORD         4        /* .word */
  104. #define GR_BYTE        5        /* .byte */
  105. #define GR_RMW        6        /* .blkb */
  106. #define    GR_RMB        7        /* .blkb */
  107. #define GR_ONOFF    8        /* on-off flag */
  108. #define    GR_RADIX    9        /* .radix */
  109. #define    GR_END        10        /* .end */
  110.  
  111. #define GR_FMT1        11        /* dual operand            */
  112. #define GR_FMT2        12        /* single operand        */
  113. #define GR_FMT3        13        /* bra and jsr            */
  114. #define GR_FMT4        14        /* implied (no operand)        */
  115. #define GR_FMT5        15        /* push                */
  116. #define GR_FMT6        16        /* exch                */
  117. #define GR_FMT7        17        /* srch                */
  118. #define GR_FMT8        18        /* move                */
  119.  
  120. #define GR_REG        19        /* registers            */
  121. #define GR_CC        81        /* condition codes        */
  122. #define GR_EQU        82        /* .equ directive        */
  123.  
  124.  
  125. /*
  126.  * addressing modes 
  127.  */
  128. #define AM_RD        0        /* register direct        */
  129. #define AM_IN        1        /* indirect            */
  130. #define AM_IP        2        /* indirect w/post-inct        */
  131. #define AM_IX        3        /* indexed            */
  132.  
  133. #define BM_R        23        /* register indirect        */
  134. #define BM_A        24        /* absolute            */
  135. #define BM_L        25        /* relative            */
  136. #define BM_I        26        /* indexed            */
  137.  
  138.  
  139. /* flags used inside the assembler */
  140. #define SF_MDF    01        /* Multiply defined */
  141. #define SF_ASG    02        /* Defined by assignment */
  142. #define S_UND    00        /* Undefined */
  143. #define S_ABS    01        /* Absolute */
  144. #define S_VALID    02        /* defined */
  145. #define    S_DEF    04        /* defined pass 2 */
  146.  
  147.  
  148. /* listing flags */
  149. #define NOCODLIS    0
  150. #define EMPTYLIS    1
  151. #define ALLLIS        2
  152.  
  153.  
  154. /* tables */
  155. extern    struct    sym pst[];    /* Opcode table */
  156. extern    struct    sym ust[];    /* User symbols */
  157. extern    struct    reflst reftab[]; /* Reference list */
  158. extern    int pstsize;        /* End of pst */
  159. extern    struct    reflst *refptr;    /* End of Reference table */
  160.  
  161.  
  162.  
  163. /* files */
  164. extern    FILE    *ifp;        /* Source */
  165. extern    FILE    *lfp;        /* Listing */
  166. extern    FILE    *ofp;        /* Object */
  167.  
  168.  
  169. extern     int    radix;        /* default radix */
  170.  
  171.  
  172. /* flags */
  173. extern    int    lflag;        /* -l flag */
  174. extern    int    nflag;        /* -n flag */
  175.  
  176. /* position  */
  177. extern    int    pass;        /* Which pass? */
  178. extern    int    lineno;        /* Line number */
  179.  
  180. /* line assembly */
  181. extern    int    opcode;        /* instuction opcode */
  182.  
  183. /* buffers */
  184. extern    char    *sptr;        /* Source pointer */
  185. extern    char    sbuf[];        /* Source buffer */
  186. extern    int    *cptr;        /* Listing code pointer */
  187. extern    int    cbuf[];     /* Listing code buffer */
  188. extern    char    *eptr;         /* Error pointer */
  189. extern    char    ebuf[];        /* Error buffer */
  190. extern    int    cadr;        /* object line address */
  191. extern    int    crec;        /* next object word */
  192. extern    int    crbf[CBMAX];    /* object code buffer */
  193.  
  194.  
  195. extern    int    refcnt;        /* Count of references */
  196. extern    struct    sym *dot;    /* location counter */
  197.  
  198. /* listing flags */
  199. extern int listmode;
  200. extern int listaddr;
  201.  
  202. /*
  203.  * Functions.
  204.  */
  205. extern    struct    sym *ustlookup();    /* Search */
  206. extern    struct    sym *pstlookup();    /* Search */
  207.